package com.jiangjiang.eshop.commodity.state;

import com.jiangjiang.eshop.commodity.constant.GoodsStatus;
import com.jiangjiang.eshop.commodity.dto.GoodsDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName GoodsStateFactory
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/17 10:22
 * @Version 1.0
 **/
@Component
public class GoodsStateFactory {
    @Autowired
    private WaitForApproveGoodsState waitForApproveGoodsState;
    @Autowired
    private WaitForPutOnShelvesGoodsState waitForPutOnShelvesGoodsState;
    @Autowired
    private ApproveRejectGoodsState approveRejectGoodsState;
    @Autowired
    private PuttedOnShelvesGoodsState puttedOnShelvesGoodsState;
    @Autowired
    private DefaultGoodsState defaultGoodsState;

    /**
     * 获取商品对应的状态组件
     *
     * @param goods 商品
     * @return 状态组件
     */
    public GoodsState get(GoodsDTO goods) {
        if(GoodsStatus.WAIT_FOR_APPROVE.equals(goods.getStatus())) {
            return waitForApproveGoodsState;
        } else if(GoodsStatus.WAIT_FOR_PUT_ON_SHELVES.equals(goods.getStatus())) {
            return waitForPutOnShelvesGoodsState;
        } else if(GoodsStatus.APPROVE_REJECT.equals(goods.getStatus())) {
            return approveRejectGoodsState;
        } else if(GoodsStatus.PUTTED_ON_SHELVES.equals(goods.getStatus())) {
            return puttedOnShelvesGoodsState;
        } else {
            return defaultGoodsState;
        }

    }
}
